<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function getLogisticsStatus(str) {
            let arr = str.split('-')
            // console.log(arr[2]);
            if (arr[2] === undefined || arr.length > 3) {
                console.log(null);
            } else {
                let obj = {
                    company: arr[0],
                    date: arr[1],
                    serialNumber: arr[2]
                }
                console.log(obj);
            }

        }
        
        // function getLogisticsStatus(str) {
        //     let arr = str.split('-')
        //     // console.log(arr[2]);
        //     arr.forEach(ele => {
        //         if (ele) {
                    
        //         }
        //         let obj = {
        //             company: arr[0],
        //             date: arr[1],
        //             serialNumber: arr[2]
        //         }                              
        //     });          
        // }

        getLogisticsStatus('SF-20230217-000001');
        // 输出：{ company: 'SF', date: '20230217', serialNumber: '000001' }

        getLogisticsStatus('YTO-20230217-000002');
        // 输出：{ company: 'YTO', date: '20230217', serialNumber: '000002' }

        getLogisticsStatus('SF-20230217-000003-TEST');
        // 输出：null

        getLogisticsStatus('SF-20230217');
        // 输出：null

        getLogisticsStatus('SF-20230217000004');

    </script>
</body>

</html>